/**
 *   Copyright (c) fanguangping. All rights reserved.
 *   The use and distribution terms for this software are covered by the
 *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *   which can be found in the file epl-v10.html at the root of this distribution.
 *   By using this software in any fashion, you are agreeing to be bound by
 * 	 the terms of this license.
 *   You must not remove this notice, or any other, from this software.
 **/
package org.jfunny.core.util;

import org.apache.commons.lang.StringUtils;

/**
 * 字符串处理工具类
 * 
 * @author fanguangping
 * 
 * 
 */
public class StringUtil extends StringUtils {
	public static final String UTF8_BOM = "\uFEFF";

	/**
	 * 移除注释
	 * @param source
	 * @param commentPrefix
	 * @return
	 */
	public static String removeComments(String source, String commentPrefix) {
		StringBuffer buffer = new StringBuffer();

		String[] lines = source.split("\n");
		for (String line : lines) {
			if (!isBlank(line) && !line.startsWith(commentPrefix)) {
				buffer.append(line);
				buffer.append("\n");
			}
		}
		return buffer.toString();
	}

	/**
	 * 移除UTF8的BOM信息
	 * @param s
	 * @return
	 */
	public static String removeUTF8BOM(String s) {
		if (!isBlank(s) && s.startsWith(UTF8_BOM)) {
			s = s.substring(1);
		}
		return s;
	}

}
